<?php
/**
 * dar模型
 *
 * @version $Id: IDarModel.php 312 2008-04-23 16:29:38Z iwind $
 * @package util.dar
 * @since 0.0.3
 */
class IDarModel extends IObject {
	/**
	 * 表
	 *
	 * @var IDarTable
	 */
	private $table;
	
	private $domainClass;
	
	private $provider;
	
	private $name;
	
	/**
	 * 构造
	 *
	 * @since 0.0.3
	 */
	public function __construct() {
		
	}
	
	/**
	 * 设置表
	 *
	 * @param IDarTable $table 表
	 * @since 0.0.3
	 */
	public function setTable($table) {
		if (is_object($table) && ($table instanceof IDarTable)) {
			$this->table = $table;
			$this->table->setModel($this);
		}
		else {
			throw new IDarException("table definition must be an instance of IDarTable or an array");
		}
	}
	
	/**
	 * 取得表
	 *
	 * @return IDarTable
	 * @since 0.0.3
	 */
	public function getTable() {
		return $this->table;
	}

	
	/**
	 * 设置域对象类名
	 *
	 * @param string $domainClass 域对象类的名称
	 * @since 0.0.3
	 */
	public function setDomainClass($domainClass) {
		$this->domainClass = $domainClass;
	}
	
	/**
	 * 取得域对象类名
	 *
	 * @return string
	 * @since 0.0.3
	 */
	public function getDomainClass() {
		return $this->domainClass;
	}
	
	/**
	 * 新建域对象
	 *
	 * @return IDarDomain
	 * @since 0.0.3
	 */
	public function createDomain() {
		$class = $this->domainClass;
		if (!class_exists($class, false)) {
			throw new IDarException("domain class '{$class}' does not exist");
		}
		$domain = new $class();
		if (!($domain instanceof IDarDomain)) {
			throw new IDarException("domain class must be inherited from IDarDomain class");
		}
		return $domain;
	}
	
	/**
	 * 设置驱动
	 *
	 * @param IDarProvider $provider 驱动
	 * @since 0.0.3
	 */
	public function setProvider(IDarProvider $provider) {
		$this->provider = $provider;
	}
	
	/**
	 * 取得驱动
	 *
	 * @return IDarProvider
	 * @since 0.0.3
	 */
	public function getProvider() {
		return $this->provider;
	}
	
	/**
	 * 设置名称
	 *
	 * @param string $name 名称
	 * @since 0.0.3
	 */
	public function setName($name) {
		$this->name = $name;
	}
	
	/**
	 * 取得名称
	 *
	 * @return string
	 * @since 0.0.3
	 */
	public function getName() {
		return $this->name;
	}
}

?>